<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>axios演示案例</title>
</head>
<body>
  <div id="box">
    <h2>从网络获取省级案例！</h2>
    <template v-if="netData.length!=0">
      <table border="1" cellspacing="0">
        <tr>
          <td>编号</td>
          <td>省级名称</td>
        </tr>
        <tr v-for="(it,i) in netData">
          <td>{{it.id}}</td>
          <td>{{it.name}}</td>
        </tr>
      </table>
    </template>
    <template v-else>
      <div>您还没有从网络上获取数据，或者获取的数据为空！</div>
    </template>

    <button v-on:click="getNetData()">点击我，从网络获取数据</button>
  </div>
  

  <script src="./vue.js"></script>
  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  <script>
    new Vue({
      el:'#box',
      data:{
        netData:""
      },
      methods: {
        getNetData:function(){
          console.log("abc");
          axios.get("/china.json")
          .then(res => {
            console.log(res);            
            this.netData=res.data;
          })
          .catch(function(err){
            console.log(err)
          })          
        }
      },
    })
  </script>
  
</body>
</html>